#include "scene.h"
#include <GL/gl.h>
#include "icgobject.h"
#include "ilightsource.h"

Scene::Scene()
{
}

void Scene::addObject(ICgObject *obj)
{
    objects_.push_back(obj);
}

void Scene::addLightSource(ILightSource *light_source)
{
    light_sources_.push_back(light_source);
}

void Scene::setCamera(const Camera &camera)
{
    camera_ = camera;
}

Camera Scene::camera() const
{
    return camera_;
}

std::vector<ICgObject*> Scene::objects() const
{
    return objects_;
}

std::vector<ILightSource*> Scene::light_sources() const
{
    return light_sources_;
}

void Scene::set_background_color(CgColor bgcolor)
{
    bgcolor_ = bgcolor;
}

CgColor Scene::background_color() const
{
    return bgcolor_;
}

Scene* Scene::clone() const
{
    Scene *new_scene = new Scene();
    for(size_t i = 0 ; i < objects_.size() ; i++) {
        ICgObject *obj = objects_[i];
        new_scene->addObject(obj->clone());
    }
    for(size_t i = 0 ; i < light_sources_.size() ; i++) {
        ILightSource *light = light_sources_[i];
        new_scene->addLightSource(light->clone());
    }
    new_scene->setCamera(this->camera_);
    new_scene->bgcolor_ = this->bgcolor_;

    return new_scene;
}

void Scene::set_ambient(CgColor ambient)
{
    ambient_ = ambient;
}

CgColor Scene::ambient() const
{
    return ambient_;
}

void Scene::opengl_setup_ambient_light() const
{
    GLfloat gl_ambient[] = {ambient_.r(), ambient_.g(), ambient_.b(), 1.0};
    glLightModelfv(GL_LIGHT_MODEL_AMBIENT, gl_ambient);
}
